<template>
  <el-menu
    background-color="#333744"
    text-color="#fff"
    active-text-color="rgb(64, 158, 255)"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
    :collapse="isCollapse"
    :unique-opened="open"
    router
  >
    <div class="divButton" @click="isCollapse = !isCollapse">| | |</div>

<!-- 样式穿透 -->
    <el-submenu :index=" '/' + firstItem.path " v-for="(firstItem, i) in menuList" :key="i">
      <!-- 第一层标题导航 -->
      <template slot="title">
        <i :class="[iconList[i].icon]"></i>
        <span> {{firstItem.authName}} </span>
      </template>
      <!-- 第二层标题导航 -->
      <el-menu-item
        :index=" '/' + secondItem.path "
        class="el-icon-menu"
        style="padding-left: 50px"
        v-for="(secondItem, j) in firstItem.children"
        :key="j"
      >
        {{secondItem.authName}}
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
import { getMenuList } from "../api/index.js"
export default {
  data() {
    return {
      isCollapse: false,
      open: true,
      iconList: [{icon:'el-icon-location'}, {icon:'el-icon-s-management'}, {icon:'el-icon-s-goods'}, {icon:'el-icon-s-order'}, {icon:'el-icon-data-line'}],
      menuList: []
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    async initMenuList() {
      let { data, meta: { msg, status } } = await getMenuList()
      if(status != 200) this.$message.error(msg);
      // console.log(data);
      this.menuList = data;
    }
  },

  created() {
    this.initMenuList()
  }
};
</script>

<style scoped lang="less">
.el-menu {
  box-sizing: border-box;
  overflow: hidden;
  height: 2000px;
}
.el-submenu :hover,
el-menu-item:hover {
  background-color: rgb(41, 44, 54);
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}


.divButton {
  color: #fff;
  // margin-bottom: 0;
  height: 20px;
  line-height: 20px;
  text-align: center;
  width: 100%;
  font-size: 14px;
  vertical-align: bottom;
  background-color: rgb(74, 80, 100);
  & :hover {
    background-color: rgb(74, 80, 100) !important;
  }
}
</style>
